//
//  BaseNavigationViewController.swift
//  SinaWeibo
//
//  Created by Tony-ztb on 15/12/25.
//  Copyright © 2015年 Tony-ztb. All rights reserved.
//

import UIKit

class BaseNavigationViewController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // 设置返回手势的代理
        interactivePopGestureRecognizer?.delegate = self
        // Do any additional setup after loading the view.
    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count != 0 {
            
            // 隐藏tabbar
            viewController.hidesBottomBarWhenPushed = true
            
            let btn = UIButton(backImageName: nil, title: "取消", fontSize: 16, color: UIColor.grayColor(), imageName: "navigationbar_back_withtext")
            btn.addTarget(self, action: "cancleComment", forControlEvents: .TouchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
            
        }
        // 调用父类方法
        super.pushViewController(viewController, animated: animated)
        
    }

    
    @objc private func cancleComment() {
        popViewControllerAnimated(true)
    }
    
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        if childViewControllers.count == 1 {
            return false
        }
        
        return true
    }
    
}
